extends Node

const _pre_hit_label = preload("res://ui/HitLabel.tscn")

var map:Node2D # 游戏场景节点
var player:Player # 玩家节点
signal on_game_start() #游戏开始信号


#造成伤害
#origin 原始 target 目标
func damage(origin:Node2D,target:Node2D,is_crit:bool):
	if origin is Player && target is BaseEnemy: # 玩家对怪物造成伤害
		if is_crit:
			target.enemy_data.current_hp -= GameProperties.get_weapon_property("damage") * GameProperties.get_weapon_property("critical_damage")
		else:	
			target.enemy_data.current_hp -= GameProperties.get_weapon_property("damage")
			

	
	if origin is BaseEnemy: # 怪物对玩家造成伤害
		if target is Player:
			PlayerManager.player_data.current_hp -= origin.enemy_data.damage
			#欲以此代上，终未成，望后#GameProperties.set_player_property("health",GameProperties.get_player_property("health")-origin.enemy_data.damage)

#展示飘字
func show_label(origin:Node2D,text:String):
	var instance = _pre_hit_label.instantiate()
	instance.global_position = origin.global_position
	
	map.add_child(instance)
	instance.set_text_and_color(text)


# 相机震动
func camera_offset(offset,time):
	var tween = create_tween()
	tween.tween_property(player.camera,'offset',Vector2.ZERO,time).from(offset)
